package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EquipmentConfiguration;
import com.ruoyi.system.service.IEquipmentConfigurationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备配置Controller
 * 
 * @author
 * @date 2024-04-10
 */
@Controller
@RequestMapping("/system/configuration")
public class EquipmentConfigurationController extends BaseController
{
    private String prefix = "system/configuration";

    @Autowired
    private IEquipmentConfigurationService equipmentConfigurationService;

    @GetMapping()
    public String configuration()
    {
        return prefix + "/configuration";
    }

    /**
     * 查询设备配置列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EquipmentConfiguration equipmentConfiguration)
    {
        startPage();
        List<EquipmentConfiguration> list = equipmentConfigurationService.selectEquipmentConfigurationList(equipmentConfiguration);
        return getDataTable(list);
    }

    /**
     * 导出设备配置列表
     */
    @Log(title = "设备配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EquipmentConfiguration equipmentConfiguration)
    {
        List<EquipmentConfiguration> list = equipmentConfigurationService.selectEquipmentConfigurationList(equipmentConfiguration);
        ExcelUtil<EquipmentConfiguration> util = new ExcelUtil<EquipmentConfiguration>(EquipmentConfiguration.class);
        return util.exportExcel(list, "设备配置数据");
    }

    /**
     * 新增设备配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存设备配置
     */
    @Log(title = "设备配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EquipmentConfiguration equipmentConfiguration)
    {
        return toAjax(equipmentConfigurationService.insertEquipmentConfiguration(equipmentConfiguration));
    }

    /**
     * 修改设备配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        EquipmentConfiguration equipmentConfiguration = equipmentConfigurationService.selectEquipmentConfigurationById(id);
        mmap.put("equipmentConfiguration", equipmentConfiguration);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备配置
     */
    @Log(title = "设备配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EquipmentConfiguration equipmentConfiguration)
    {
        return toAjax(equipmentConfigurationService.updateEquipmentConfiguration(equipmentConfiguration));
    }

    /**
     * 删除设备配置
     */
    @Log(title = "设备配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(equipmentConfigurationService.deleteEquipmentConfigurationByIds(ids));
    }

    /**
     * 获取站点设备配置详细信息
     */
//    @GetMapping(value = "/getInfoBySite/{site}")
//    public AjaxResult getInfoBySite(@PathVariable("site") String site)
//    {
//        return success(equipmentConfigurationService.selectEquipmentConfigurationBySite(site));
//    }
    @GetMapping("/getInfoBySite/{site}")
    @ResponseBody
    public AjaxResult getInfoBySite(@PathVariable("site") String site, ModelMap mmap)
    {
        EquipmentConfiguration equipmentConfiguration = equipmentConfigurationService.selectEquipmentConfigurationBySite(site);
        return success(equipmentConfiguration);
    }
}
